<?php

require_once('pub_inc.php');		//公共包含

$meituan = 'http://www.meituan.com/api/v2/hengyang/deals';
$f_id_s = array(107, 111, 105, 108, 106);

$m_xml = simplexml_load_file($meituan);
foreach ($m_xml->children() as $d_xml) {
	$data = $d_xml->data;
	$display = $data->display;

	$identifier = $display->identifier;

	//频道ID
	$tag = $display->tag;
	switch (split(',', $tag)[0]) {
	case '美食':
		$forum_id = $f_id_s[0];
		break;
	case '美容':
		$forum_id = $f_id_s[1];
		break;
	case '娱乐':
		$forum_id = $f_id_s[2];
		break;
	case '生活':
		$forum_id = $f_id_s[3];
		break;
	default:
		$forum_id = $f_id_s[4];
	}

	//避免频繁更新
	$topic = get_topic_by_order_l_n($identifier, $forum_id);
	if (check_topic_live($topic)) continue; 

	$title = $display->title;
	$price = $display->price;
	$price_org = $display->value;
	$icon_url = $display->image;
	$start_t_s = $display->endTime;
	$out_s_u = 'http://r.union.meituan.com/url/visit/?a=1&key=s3IK8ZAUbpkjSta1u6qDHC2EOcewxRFoPir&url=http%3A%2F%2Fhy.meituan.com%2Fdeal%2Fbuy%2F'.$identifier;
	$phone = $data->shops->shop->tel;

	//内容
	$content = $display->shortTitle.'<br>';
	$content .= $display->districtname.'<br>';
	$content .= $tag.'<br>';
	$content .= $display->merchantendtime.'<br>';
	$content .= $display->tip.'<hr>';

	foreach ($data->shops->children() as $shop) {
		$content .= $shop->name.'<br>'.$shop->tel.'<br>'.$shop->addr.'<br>'.$shop->area.'<br><hr>';
	}

	$moreimages = split(',', $display->moreimages);
	foreach ($moreimages as $img) {
		$content .= '<img src="'.$img.'"/><br>';
	}

	do_topic_add_ext_1_x($forum_id, $title, $content, $icon_url, $price, $price_org, $phone, $start_t_s, $out_s_u, $identifier, $topic['id']); 
}

foreach ($f_id_s as $forum_id) p_p_topic($forum_id); 
return true;
